/*
 * 文件名：PaymentMethodsInfoTransactionImp.java
 * 版权：Copyright by www.wootide.com
 * 描述：
 * 修改人：ozm
 * 修改时间：2013-1-30
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.service.reservation.payment.transaction.imp;

import org.springframework.beans.BeanUtils;

import com.wootide.cms.common.CMSRuntimeException;
import com.wootide.cms.common.ErrorCodes;
import com.wootide.cms.common.Page;
import com.wootide.cms.common.QueryCondition;
import com.wootide.cms.common.QueryResults;
import com.wootide.cms.common.dao.CommonDao;
import com.wootide.cms.log.syslog.RunLog;
import com.wootide.cms.service.reservation.payment.dao.PaymentMethodsInfoDao;
import com.wootide.cms.service.reservation.payment.pojo.PaymentMethodsInfo;
import com.wootide.cms.service.reservation.payment.transaction.PaymentMethodsInfoTransaction;

/**
 * 支付方式事物层实现层
 * 〈一句话功能简述〉
 * 〈功能详细描述〉
 * @author ozm
 * @version 2013-1-30
 * @see PaymentMethodsInfoTransactionImp
 * @since 2013-1-30上午9:44:19
 */
public class PaymentMethodsInfoTransactionImp implements PaymentMethodsInfoTransaction
{
   

    // 注入运行日志
    private RunLog runLog;
    
    //公共数据访问层实例
    private CommonDao commonDao;
    
    //支付方式数据访问层实例
    private PaymentMethodsInfoDao paymentMethodsInfoDao;
    
    /**
     * 
     * Description: 分页查询
     * Implement: <br>
     * @param page 分页参数
     * @param queryConditon 查询条件
     * @see
     * @return Result 结果对象
     * @author ozm2013-1-29下午1:23:32
     */
    public QueryResults queryForPages(Page page, QueryCondition queryConditon)
    {
        
        // 打印方法入口参数
        runLog.debug("page=" + page);
        runLog.debug("queryConditon=" + queryConditon);
        QueryResults queryResults = commonDao.queryForPages(page, queryConditon);
        return queryResults;
    }
    
    /**
     * 
     * Description: 添加一种支付方式
     * Implement: <br>
     * @param paymentMethodsInfo 要添加的支付方式
     * @see
     * @author ozm2013-1-29下午1:26:06
     */
    public void addOnePaymentMethods(PaymentMethodsInfo paymentMethodsInfo)
    {
        // 打印方法入口参数
        runLog.debug("paymentMethodsInfo=" + paymentMethodsInfo);
        // 根据用户名检查唯一性
        Integer num = paymentMethodsInfoDao.findNumByPaymentMethodsByName(paymentMethodsInfo.getPaymentName());
        //用户记录已经存在
        if (num > 0)
        {
            throw new CMSRuntimeException("PaymentMethodsInfo Existed!",
                    ErrorCodes.Reservation.Payment.PAYMENTMETHODSEXIST);
        }
        
        commonDao.addOneObject(paymentMethodsInfo);
        
    }
    
    /**
     * 
     * Description: 修改一种支付方式
     * Implement: <br>
     * @param paymentMethodsInfo 要修该的支付方式
     * @see
     * @return oldPaymentMethodsInfoCopy 修改的支付方式对象
     * @author ozm2013-1-29下午1:27:37
     */
    public PaymentMethodsInfo  modOnePaymentMethods(PaymentMethodsInfo paymentMethodsInfo)
    {
        // 打印方法入口参数
        runLog.debug("paymentMethodsInfo=" + paymentMethodsInfo);
        PaymentMethodsInfo oldPaymentMethodsInfo = paymentMethodsInfoDao.findOnePaymentMethodsByPaymentMethodsId(paymentMethodsInfo.getInnerIndex());
        
        //判断要修改的记录是否存在
        if (null == oldPaymentMethodsInfo)
        {
            throw new CMSRuntimeException("PaymentMethodsInfo not Exist!",
                    ErrorCodes.Reservation.Payment.PAYMENTMETHODSNOTEXIST);
        }
        
        //获取原始数据副本
        PaymentMethodsInfo oldPaymentMethodsInfoCopy = new PaymentMethodsInfo();
        BeanUtils.copyProperties(oldPaymentMethodsInfo, oldPaymentMethodsInfoCopy);
        
        //修改
        oldPaymentMethodsInfo.setPaymentName(paymentMethodsInfo.getPaymentName());
        oldPaymentMethodsInfo.setDiscount(paymentMethodsInfo.getDiscount());
        oldPaymentMethodsInfo.setPaymentDesc(paymentMethodsInfo.getPaymentDesc());
        return oldPaymentMethodsInfoCopy;
    }
    
    /**
     * 
     * Description: 删除支付方式
     * Implement: <br>
     * @param innerIndex 要删除的支付方式id
     * @return
     * @see
     * @return PaymentMethodsInfo 要删除的支付方式信息
     * @author ozm2013-1-29下午4:17:56
     */
    public PaymentMethodsInfo delOnePaymentMethods(Integer innerIndex)
    {
        PaymentMethodsInfo oldPaymentMethodsInfo = paymentMethodsInfoDao.findOnePaymentMethodsByPaymentMethodsId(innerIndex);
        //判断要删除的记录是否存在
        if (null == oldPaymentMethodsInfo)
        {
            throw new CMSRuntimeException("OrderByInfo not Exist!",
                    ErrorCodes.Reservation.Payment.PAYMENTMETHODSNOTEXIST);
        }
        
        commonDao.delOneObject(oldPaymentMethodsInfo);
        //        BeanUtils.copyProperties(oldUserInfo, oldUserInfoCopy);
        return oldPaymentMethodsInfo;
    }
    
    /**
     * 
     * Description: 通过索引获取支付方式
     * Implement: <br>
     * @param innerIndex 指定的支付方式ID
     * @see
     * @return RoleInfo 要查询的支付方式
     * @author ozm2013-1-29下午3:55:17
     */
    public PaymentMethodsInfo viewOnePaymentMethods(Integer innerIndex)
    {
        // 打印方法入口参数
        runLog.debug("innerIndex=" + innerIndex);
        PaymentMethodsInfo paymentMethodsInfo = paymentMethodsInfoDao.findOnePaymentMethodsByPaymentMethodsId(innerIndex);
        return paymentMethodsInfo;
    }

    public RunLog getRunLog()
    {
        return runLog;
    }

    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }

    public CommonDao getCommonDao()
    {
        return commonDao;
    }

    public void setCommonDao(CommonDao commonDao)
    {
        this.commonDao = commonDao;
    }

    public PaymentMethodsInfoDao getPaymentMethodsInfoDao()
    {
        return paymentMethodsInfoDao;
    }

    public void setPaymentMethodsInfoDao(PaymentMethodsInfoDao paymentMethodsInfoDao)
    {
        this.paymentMethodsInfoDao = paymentMethodsInfoDao;
    }
  

}
